package com.longtengyuyun.socke_demo.sock;

import java.io.OutputStream;
import java.net.Socket;
import java.util.Arrays;

/**
 * @author ZhaoYunLong
 * @date 2022/4/14
 * @description
 */
public class SocketTwoClient {


    public static void main(String[] args) {

        try {
            String host = "127.0.0.1";
            int port = 5555;
            Socket socket = new Socket(host, port);

            OutputStream outputStream = socket.getOutputStream();
            String content = "这是一个整包";

            byte[] contentBytes = content.getBytes("utf-8");
            int length = contentBytes.length;

            byte[] lengthBytes = Utils.intToBytes(length);

            byte[] resultBytes = new byte[4 + length];

            System.arraycopy(lengthBytes, 0, resultBytes, 0, lengthBytes.length);
            System.arraycopy(contentBytes, 0, resultBytes, 4, contentBytes.length);

            for (int i = 0; i<10;i++) {
                outputStream.write(resultBytes);
            }
            Thread.sleep(20000);
            outputStream.close();
            socket.close();
        } catch (Exception e) {
            e.printStackTrace();
        }


    }


}
